//
//  BaseViewController.m
//  MiaMind
//
//  Created by Vill on 2023/11/23.
//

#import "BaseViewController.h"
//#import "UINavigationController+FDFullscreenPopGesture.h"
#import <TZImagePickerController/TZImagePickerController.h>

@interface BaseViewController ()


@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.clearColor;
    self.fd_prefersNavigationBarHidden = YES;
}

// 关闭页面
-(void)dissMissAction{
    // 获取当前视图控制器的大小
    CGRect viewControllerFrame = self.view.frame;
    // 计算模态视图的最终位置
    CGRect modalViewFinalFrame = CGRectMake(0, viewControllerFrame.size.height, viewControllerFrame.size.width, viewControllerFrame.size.height);
    // 开始动画
    [UIView animateWithDuration:0.3 animations:^{
        // 修改模态视图的frame属性，让它移动到最终位置
        self.view.frame = modalViewFinalFrame;
    } completion:^(BOOL finished) {
        // 动画完成后执行dismissViewControllerAnimated方法
        [self dismissViewControllerAnimated:NO completion:nil];
    }];

}

#pragma mark - 选择图片 -
///  选择图片
-(void)chooseRictureWithResult:(ChooseRictureBackResult )chooseImageResult{
    TZImagePickerController * imagePicker = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil];
    imagePicker.view.backgroundColor = [UIColor blackColor];
    imagePicker.allowTakePicture = YES;
    imagePicker.allowPickingVideo = NO;
    imagePicker.allowPickingImage = YES;
    imagePicker.allowPickingOriginalPhoto = YES;
    imagePicker.sortAscendingByModificationDate = NO;
    imagePicker.minPhotoWidthSelectable = 100;
    imagePicker.minPhotoHeightSelectable = 100;
    imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:imagePicker animated:YES completion:nil];
    [imagePicker setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
//        if (!isSelectOriginalPhoto) {
//            if (chooseImageResult) {
//                chooseImageResult(photos[0]);
//            }
//        }else{
//            NSMutableArray *chooseImageArray = [NSMutableArray array];
//            for (int i = 0; i < assets.count; i++) {
//                PHAsset *asset = (PHAsset*)assets[i];
//                NSString *locoId = asset.localIdentifier;
//                PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[locoId] options:nil];
//                PHAsset *assetbool = fetchResult.firstObject;
//                if (assetbool) {
//                    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
//                    options.synchronous = YES;
//                    [[PHImageManager defaultManager] requestImageForAsset:assetbool targetSize:CGSizeMake(asset.pixelWidth, asset.pixelHeight) contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
//                        [chooseImageArray addObject:result];
//                    }];
//                }
//            }
//            if (chooseImageArray.count != 0) {
//                UIImage *image = chooseImageArray.firstObject;
//                if (image
//                    &&chooseImageResult) {
//                    chooseImageResult(image);
//                }
//            }
//        }
        UIImage *image = photos.firstObject;
        if (image
            &&chooseImageResult) {
            chooseImageResult(image);
        }
    }];
}


@end
